package de.ff7rl.core.effects.performer;

import java.util.List;

import de.ff7rl.core.battle.BattleParticipant;
import de.ff7rl.core.effects.EffectPerformer;

public class ManipulateHealthPoints implements EffectPerformer {

  /**
   * {@inheritDoc}
   */
  @Override
  public void perform(final BattleParticipant theBattleParticipant, final List<Object> theArguments) {
    final int points = getPointsToIncrease(theArguments);
    theBattleParticipant.getHealthPoints().increaseCurrent(points);
  }

  private int getPointsToIncrease(final List<Object> theArguments) {
    if (theArguments == null || theArguments.isEmpty()) {
      throw new IllegalArgumentException(String.format("No arguments provided to %s.", getClass()));
    }
    final Object firstArgument = theArguments.get(0);
    try {
      return Integer.parseInt(firstArgument.toString());
    } catch (final NumberFormatException e) {
      throw new IllegalArgumentException(String.format("Unable to parse number from argument %s.", firstArgument), e);
    }
  }

}
